﻿using King.Box.Utils.Global;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Text;
using System.Threading.Tasks;

namespace King.Box.OpenApi.Service
{
    public class NotifyService
    {
        public void MailNotify(string subject, string body, string mailTo = null)
        {
            if (string.IsNullOrEmpty(mailTo))
                mailTo = GlobalConfig.Mail_UserName;

            MailMessage mailMessage = new MailMessage()
            {
                From = new MailAddress(GlobalConfig.Mail_UserName),
                Subject = subject,
                Body = body
            };
            mailMessage.To.Add(new MailAddress(mailTo));

            //实例化一个SmtpClient类。
            SmtpClient client = new SmtpClient()
            {
                Host = GlobalConfig.Mail_Server,
                EnableSsl = true,
                UseDefaultCredentials = false,
                Credentials = new NetworkCredential(GlobalConfig.Mail_UserName, GlobalConfig.Mail_UserPwd)
            };

            client.Send(mailMessage);
        }
    }
}
